object CompDM: TCompDM
  OldCreateOrder = False
  OnCreate = DataModuleCreate
  Height = 374
  Width = 901
  object SvodMDBConnection: TADOConnection
    LoginPrompt = False
    Mode = cmReadWrite
    Provider = 'SQLOLEDB.1'
    Left = 32
    Top = 16
  end
  object SelectPlatPredpr: TADOQuery
    Connection = SvodMDBConnection
    Parameters = <>
    SQL.Strings = (
      'SELECT idPredpr, NamePredprShort'
      'FROM tbPredpr'
      'WHERE idPredpr=idPlat'
      'ORDER BY NamePredprShort')
    Left = 120
    Top = 16
  end
  object SelectPlatPredprDS: TDataSource
    DataSet = SelectPlatPredpr
    Left = 120
    Top = 64
  end
  object ImageList_16: TImageList
    Left = 24
    Top = 280
    Bitmap = {
      [encoded data, 17216 characters]
      000000000000}
  end
  object ImageList_24: TImageList
    Height = 24
    Width = 24
    Left = 64
    Top = 280
    Bitmap = {
      [encoded data, 57344 characters]
      000000000000}
  end
  object CompareMemTableEh: TMemTableEh
    FieldDefs = <
      item
        Name = 'idPredpr'
        DataType = ftLargeint
        Precision = 15
      end
      item
        Name = 'invoicefullname'
        DataType = ftString
        Size = 25
      end
      item
        Name = 'datetrans'
        DataType = ftDateTime
      end
      item
        Name = 'status'
        DataType = ftWord
        Precision = 15
      end
      item
        Name = 'recipientname'
        DataType = ftString
        Size = 200
      end
      item
        Name = 'signerfio'
        DataType = ftString
        Size = 70
      end
      item
        Name = 'namepredpr'
        DataType = ftString
        Size = 150
      end
      item
        Name = 'docnumber'
        DataType = ftString
        Size = 50
      end
      item
        Name = 'docdate'
        DataType = ftDateTime
      end
      item
        Name = 'ndsexcel'
        DataType = ftBCD
        Precision = 18
        Size = 3
      end
      item
        Name = 'ndsspr'
        DataType = ftBCD
        Precision = 18
        Size = 3
      end
      item
        Name = 'ndsinvoice'
        DataType = ftBCD
        Precision = 18
        Size = 3
      end
      item
        Name = 'totalcostinv'
        DataType = ftBCD
        Precision = 18
        Size = 3
      end
      item
        Name = 'totalcostvatinv'
        DataType = ftBCD
        Precision = 18
        Size = 3
      end
      item
        Name = 'filial'
        DataType = ftSmallint
        Precision = 15
      end
      item
        Name = 'svplace'
        DataType = ftString
        Size = 1
      end
      item
        Name = 'numbuhspr'
        DataType = ftString
        Size = 10
      end
      item
        Name = 'numdocpart'
        DataType = ftString
        Size = 50
      end>
    FetchAllOnOpen = True
    IndexDefs = <>
    Params = <>
    DataDriver = SelectSvodInvDSDEh
    StoreDefs = True
    OnCalcFields = CompareMemTableEhCalcFields
    Left = 487
    Top = 66
    object CompareMemTableEhnamepredpr: TStringField
      FieldName = 'namepredpr'
      ReadOnly = True
      Size = 150
    end
    object CompareMemTableEhinvoicefullname: TStringField
      FieldName = 'invoicefullname'
      ReadOnly = True
      Size = 25
    end
    object CompareMemTableEhdatetrans: TDateTimeField
      FieldName = 'datetrans'
      ReadOnly = True
    end
    object CompareMemTableEhStatusText: TStringField
      FieldKind = fkCalculated
      FieldName = 'StatusText'
      ReadOnly = True
      Size = 33
      Calculated = True
    end
    object CompareMemTableEhrecipientname: TStringField
      FieldName = 'recipientname'
      ReadOnly = True
      Size = 200
    end
    object CompareMemTableEhsignerfio: TStringField
      FieldName = 'signerfio'
      ReadOnly = True
      Size = 70
    end
    object CompareMemTableEhdocnumber: TStringField
      FieldName = 'docnumber'
      ReadOnly = True
      Size = 50
    end
    object CompareMemTableEhdocdate: TDateTimeField
      FieldName = 'docdate'
      ReadOnly = True
    end
    object CompareMemTableEhndsexcel: TBCDField
      FieldName = 'ndsexcel'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object CompareMemTableEhndsspr: TBCDField
      FieldName = 'ndsspr'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object CompareMemTableEhndsinvoice: TBCDField
      FieldName = 'ndsinvoice'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object CompareMemTableEhndsdiff: TBCDField
      FieldKind = fkCalculated
      FieldName = 'ndsdiff'
      Calculated = True
    end
    object CompareMemTableEhtotalcostinv: TBCDField
      FieldName = 'totalcostinv'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object CompareMemTableEhtotalcostvatinv: TBCDField
      FieldName = 'totalcostvatinv'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object CompareMemTableEhfilial: TSmallintField
      FieldName = 'filial'
      ReadOnly = True
    end
    object CompareMemTableEhsvplace: TStringField
      FieldName = 'svplace'
      ReadOnly = True
      Size = 1
    end
    object CompareMemTableEhnumbuhspr: TStringField
      FieldName = 'numbuhspr'
      Size = 10
    end
    object CompareMemTableEhnumdocpart: TStringField
      FieldName = 'numdocpart'
      Size = 50
    end
    object CompareMemTableEhidPredpr: TLargeintField
      FieldName = 'idPredpr'
      ReadOnly = True
    end
    object CompareMemTableEhstatus: TWordField
      FieldName = 'status'
      ReadOnly = True
    end
  end
  object CompareMemTableEhDS: TDataSource
    DataSet = CompareMemTableEh
    Left = 520
    Top = 64
  end
  object CrExcelTemp: TADOQuery
    Connection = SvodMDBConnection
    CursorType = ctStatic
    CommandTimeout = 120
    Parameters = <>
    SQL.Strings = (
      'if object_id('#39'tempdb..#svexceltmp'#39','#39'U'#39') is not NULL'
      'drop table tempdb..#svexceltmp'
      ''
      'CREATE TABLE tempdb..#svexceltmp('
      'idPredpr bigint,'
      'namePredpr varchar(200),'
      'invoicefullname varchar(25),'
      'datetrans datetime,'
      'status tinyint,'
      'recipientname varchar(200),'
      'dopunn int,'
      'signerfio varchar(70),'
      'docnumber varchar(50),'
      'docdate datetime,'
      'ndsexcel decimal(18, 3),'
      'totalcostinv decimal(18, 3),'
      'totalcostvatinv decimal(18, 3),'
      'svplace varchar(1))')
    Left = 232
    Top = 16
  end
  object InsExcelTempQ: TADOQuery
    Connection = SvodMDBConnection
    CommandTimeout = 900
    Parameters = <
      item
        Name = 'idPredpr'
        Attributes = [paSigned, paNullable]
        DataType = ftLargeint
        Precision = 19
        Size = 8
        Value = Null
      end
      item
        Name = 'namePredpr'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 200
        Value = Null
      end
      item
        Name = 'invoicefullname'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 25
        Value = Null
      end
      item
        Name = 'datetrans'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'status'
        Attributes = [paNullable]
        DataType = ftWord
        Precision = 3
        Size = 1
        Value = Null
      end
      item
        Name = 'recipientname'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 200
        Value = Null
      end
      item
        Name = 'dopunn'
        Attributes = [paSigned, paNullable]
        DataType = ftInteger
        Precision = 10
        Size = 4
        Value = Null
      end
      item
        Name = 'signerfio'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 70
        Value = Null
      end
      item
        Name = 'docnumber'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'docdate'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'ndsexcel'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'totalcostinv'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'totalcostvatinv'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'svplace'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 1
        Value = Null
      end>
    SQL.Strings = (
      
        'INSERT INTO #svexceltmp(idPredpr, namePredpr,invoicefullname,dat' +
        'etrans,status, recipientname, dopunn, signerfio, docnumber,docda' +
        'te,ndsexcel,totalcostinv,totalcostvatinv,svplace)'
      
        'VALUES (:idPredpr,:namePredpr,:invoicefullname,:datetrans,:statu' +
        's, :recipientname, :dopunn, :signerfio, :docnumber,:docdate,:nds' +
        'excel,:totalcostinv,:totalcostvatinv,:svplace)'
      '')
    Left = 272
    Top = 16
  end
  object SelectSvodInvDSDEh: TDataSetDriverEh
    ProviderDataSet = SelectSvodInv
    Left = 456
    Top = 64
  end
  object ObjMDBConnection: TADOConnection
    LoginPrompt = False
    Provider = 'SQLOLEDB.1'
    Left = 32
    Top = 200
  end
  object InsInvProvData: TADOQuery
    Connection = ObjMDBConnection
    CommandTimeout = 900
    Parameters = <
      item
        Name = 'FirstDate'
        DataType = ftString
        Size = 10
        Value = '01.01.2020'
      end
      item
        Name = 'SecondDate'
        DataType = ftString
        Size = 10
        Value = '31.01.2020'
      end>
    SQL.Strings = (
      'SET DATEFORMAT DMY'
      ''
      'DECLARE @FirstDate DATETIME,'
      '        @SecondDate DATETIME,'
      '        @dopUnn smallint'
      ''
      'SET @FirstDate = CAST(:FirstDate AS DATETIME)'
      'SET @SecondDate = CAST(:SecondDate AS DATETIME)'
      ''
      
        'SELECT @dopUnn=dopUNN FROM tbPredpr WHERE idPredpr=(SELECT idPre' +
        'dpr FROM tbNastrPredpr) '
      ''
      
        'INSERT INTO #inv_prov(fullName, documentType, invStatus, dateTra' +
        'ns, docNumber, docDate, sprSum, totalVat, totalCost, totalCostVa' +
        't, dopUnn, NumBuhSpr, idPredpr, globalcode, NumDocPart)'
      
        'SELECT inv.Fullname, inv.documentType, inv.invStatus, inv.dateTr' +
        'ansaction, ISNULL(inv.docNumber, spr.NumDoc) AS docNumber,      ' +
        '       '
      
        '             ISNULL(spr.DataDoc, inv.docDate) AS docDate, spr.Su' +
        'mm, inv.totalVat, inv.totalCost, inv.totalCostVat, @dopUnn as do' +
        'pUnn,'
      
        '             spr.NumBuhSpr, ISNULL(spr.idPredpr, inv.idSender), ' +
        ' CASE WHEN RIGHT(ISNULL(spr.globalcode, inv.globalcode), 1) = '#39'*' +
        #39' THEN NULL ELSE ISNULL(spr.globalcode, inv.globalcode) END,'
      '             spr.NumDocPart'
      'FROM (-- '#1048#1089#1093#1086#1076#1085#1099#1077' '#1080' '#1044#1086#1087#1086#1083#1085#1080#1090#1077#1083#1100#1085#1099#1077' '#1073#1077#1079' '#1089#1089#1099#1083#1082#1080' '#1069#1057#1063#1060' '
      
        '            SELECT prov.UNN+'#39'-'#39'+CAST(inv.compilingYear AS VARCHA' +
        'R)+'#39'-'#39'+RIGHT('#39'0000000000'#39'+CAST(inv.number AS VARCHAR),10) AS Ful' +
        'lname, his.invStatus, '
      '                         -- doc.docNumber,'
      
        '                         substring(doc.docNumber, patindex('#39'%[^0' +
        ']%'#39', doc.docNumber), 50) AS docNumber,'
      
        '                         doc.docDate, inv.totalVat, inv.totalCos' +
        't, inv.totalCostVat, inv.documentType, inv.idSender, prov.global' +
        'code, inv.dateTransaction'
      '            FROM invoices inv'
      
        '                       INNER JOIN history his ON inv.idSender=hi' +
        's.idSender AND inv.compilingYear=his.compilingYear AND inv.numbe' +
        'r=his.number'
      
        '                       LEFT JOIN documents doc ON inv.idSender=d' +
        'oc.idSender AND inv.compilingYear=doc.compilingYear AND inv.numb' +
        'er=doc.number'
      
        '                       INNER JOIN tbPredpr prov ON prov.idPredpr' +
        '=inv.idProvider'
      
        '            WHERE inv.sv=1 and documentType in (1, 4) and ((inv.' +
        'dateTransaction BETWEEN @FirstDate and @SecondDate) or (doc.docD' +
        'ate BETWEEN @FirstDate and @SecondDate)) '
      ''
      '            UNION'
      ''
      
        '      -- '#1044#1086#1087#1086#1083#1085#1080#1090#1077#1083#1100#1085#1099#1077' '#1080' '#1048#1089#1087#1088#1072#1074#1083#1077#1085#1085#1099#1077' '#1069#1057#1063#1060' ('#1076#1086#1087#1086#1083#1085#1080#1090#1077#1083#1100#1085#1086' '#1087#1088#1086#1074#1077 +
        #1088#1103#1077#1090#1089#1103' '#1076#1072#1090#1072' '#1086#1088#1080#1075#1080#1085#1072#1083#1100#1085#1086#1081' '#1069#1057#1063#1060')'
      
        '            SELECT prov.UNN+'#39'-'#39'+CAST(inv.compilingYear AS VARCHA' +
        'R)+'#39'-'#39'+RIGHT('#39'0000000000'#39'+CAST(inv.number AS VARCHAR),10) AS Ful' +
        'lname, his.invStatus,'
      '                         -- doc.docNumber, '
      
        '                         substring(doc.docNumber, patindex('#39'%[^0' +
        ']%'#39', doc.docNumber), 50) AS docNumber,'
      
        '                         doc.docDate, inv.totalVat, inv.totalCos' +
        't, inv.totalCostVat, inv.documentType, inv.idSender, prov.global' +
        'code, inv.dateTransaction'
      '           FROM invoices inv'
      
        '                       INNER JOIN history his ON inv.idSender=hi' +
        's.idSender AND inv.compilingYear=his.compilingYear AND inv.numbe' +
        'r=his.number'
      
        '                       LEFT JOIN documents doc ON inv.idSender=d' +
        'oc.idSender AND inv.compilingYear=doc.compilingYear AND inv.numb' +
        'er=doc.number'
      
        '                       INNER JOIN tbPredpr prov ON prov.idPredpr' +
        '=inv.idProvider'
      
        '                       LEFT JOIN invoices invorg ON invorg.idSen' +
        'der=inv.idSender and CAST(Substring(inv.invoice, 11, 4) AS small' +
        'int)=invorg.compilingYear and CAST(Substring(inv.invoice, 16, 10' +
        ') AS bigint)=invorg.number'
      
        '                       LEFT JOIN documents docorg ON invorg.idSe' +
        'nder=docorg.idSender AND invorg.compilingYear=docorg.compilingYe' +
        'ar AND invorg.number=docorg.number'
      '            WHERE inv.sv=1 and inv.documentType in (2, 3) and '
      
        '                         ((inv.dateTransaction BETWEEN @FirstDat' +
        'e and @SecondDate) or (doc.docDate BETWEEN @FirstDate and @Secon' +
        'dDate) or '
      
        '                         (invorg.dateTransaction BETWEEN @FirstD' +
        'ate and @SecondDate) or (docorg.docDate BETWEEN @FirstDate and @' +
        'SecondDate))'
      '           ) inv               '
      '           FULL JOIN (-- '#1042#1099#1073#1086#1088#1082#1072' '#1089#1091#1084#1084' '#1080#1079' '#1089#1087#1088#1072#1074#1082#1080' '#1087#1086' '#1087#1088#1086#1074#1086#1076#1082#1072#1084
      
        '                              SELECT spr.NSF, SUM(spr.Summ) AS S' +
        'umm, spr.DataDoc, '
      '                                           -- spr.NumDoc, '
      
        '                                           substring(spr.NumDoc,' +
        ' patindex('#39'%[^0]%'#39', spr.NumDoc), 50) AS NumDoc,'
      
        '                                           spr.numDocPart, spr.N' +
        'umBuhSpr, spr.idPredpr, pred.globalcode'
      '                              FROM buh.dbo.tbSpravka spr'
      
        '                                         INNER JOIN buh.dbo.tbSF' +
        'ProvNDS prov ON spr.idSchetSubSchetDT=prov.IdDt AND spr.PrizAUDT' +
        '=prov.AuDt AND'
      
        '                                                                ' +
        '                                                 spr.idSchetSubS' +
        'chetKT=prov.IdKt AND spr.PrizAUKT=prov.AuKt'
      
        '                                         LEFT JOIN tbPredpr pred' +
        ' ON spr.idPredpr=pred.idPredpr'
      
        '                              WHERE (DataDoc BETWEEN @FirstDate ' +
        'and @SecondDate) AND PrizRej=1 AND Sv=0'
      '                              GROUP BY spr.NSF, spr.DataDoc, '
      '                                                -- spr.NumDoc, '
      
        '                                                substring(spr.Nu' +
        'mDoc, patindex('#39'%[^0]%'#39', spr.NumDoc), 50),'
      
        '                                                spr.numDocPart, ' +
        'spr.NumBuhSpr, spr.idPredpr, pred.globalcode) spr ON (inv.Fullna' +
        'me=Substring(spr.NSF,3,25)'
      '                             ) '
      '-- '#1059#1089#1083#1086#1074#1080#1077' '#1076#1083#1103' '#1087#1088#1077#1076#1087#1088#1080#1103#1090#1080#1103
      'ORDER BY inv.Fullname')
    Left = 144
    Top = 200
  end
  object SelectInvProvData: TADOQuery
    Connection = ObjMDBConnection
    CursorType = ctStatic
    CommandTimeout = 900
    Parameters = <>
    SQL.Strings = (
      'SELECT main.*, NULL AS Svplace'
      'FROM #inv_prov main'
      '     INNER JOIN (SELECT docNumber, sprSum, idPredpr'
      '                FROM #inv_prov'
      '                GROUP BY docNumber, sprSum, idPredpr'
      
        '                HAVING COUNT(*)=1) grp ON main.docNumber=grp.doc' +
        'Number AND main.sprSum=grp.sprSum AND main.idPredpr=grp.idPredpr'
      'WHERE main.fullName is NULL'
      ''
      'UNION ALL'
      ''
      'SELECT main.*, NULL AS Svplace'
      'FROM #inv_prov main'
      '     INNER JOIN (SELECT docNumber, sprSum, idPredpr'
      '                FROM #inv_prov'
      '                GROUP BY docNumber, sprSum, idPredpr'
      
        '                HAVING COUNT(*)>1) grp ON main.docNumber=grp.doc' +
        'Number AND main.sprSum=grp.sprSum AND main.idPredpr=grp.idPredpr'
      
        '     LEFT JOIN #inv_prov esf ON main.docNumber=esf.docNumber AND' +
        ' main.sprSum=esf.sprSum AND main.idPredpr=esf.idPredpr AND esf.f' +
        'ullName is not NULL'
      'WHERE main.fullName is NULL AND esf.fullName IS NULL'
      ''
      'UNION ALL'
      ''
      'SELECT main.*, '#39#1057#39' AS Svplace'
      'FROM #inv_prov main'
      'WHERE main.fullName is not NULL'
      'ORDER BY main.fullName')
    Left = 280
    Top = 200
    object SelectInvProvDatafullName: TStringField
      FieldName = 'fullName'
      Size = 30
    end
    object SelectInvProvDatadocumentType: TWordField
      FieldName = 'documentType'
    end
    object SelectInvProvDatainvStatus: TSmallintField
      FieldName = 'invStatus'
    end
    object SelectInvProvDatadateTrans: TDateTimeField
      FieldName = 'dateTrans'
    end
    object SelectInvProvDatadocNumber: TStringField
      FieldName = 'docNumber'
      Size = 30
    end
    object SelectInvProvDatadocDate: TDateTimeField
      FieldName = 'docDate'
    end
    object SelectInvProvDatasprSum: TBCDField
      FieldName = 'sprSum'
      Precision = 18
      Size = 3
    end
    object SelectInvProvDatatotalVat: TBCDField
      FieldName = 'totalVat'
      Precision = 18
      Size = 3
    end
    object SelectInvProvDatatotalCost: TBCDField
      FieldName = 'totalCost'
      Precision = 18
      Size = 3
    end
    object SelectInvProvDatatotalCostVat: TBCDField
      FieldName = 'totalCostVat'
      Precision = 18
      Size = 3
    end
    object SelectInvProvDatadopUnn: TSmallintField
      FieldName = 'dopUnn'
    end
    object SelectInvProvDataNumBuhSpr: TStringField
      FieldName = 'NumBuhSpr'
      Size = 10
    end
    object SelectInvProvDataidPredpr: TIntegerField
      FieldName = 'idPredpr'
    end
    object SelectInvProvDataglobalcode: TLargeintField
      FieldName = 'globalcode'
    end
    object SelectInvProvDataSvplace: TStringField
      FieldName = 'Svplace'
      ReadOnly = True
      Size = 1
    end
    object SelectInvProvDataNumDocPart: TStringField
      FieldName = 'NumDocPart'
      Size = 50
    end
  end
  object SelectDuplicateProv: TADOQuery
    Connection = ObjMDBConnection
    CursorType = ctStatic
    CommandTimeout = 900
    Parameters = <>
    SQL.Strings = (
      
        'SELECT main.NumBuhSpr, main.docNumber, main.docDate, main.sprSum' +
        ', esf.numBuhSpr AS numBuhinv, esf.fullName, esf.totalVat, pr.nam' +
        'ePredpr, main.dopUNN'
      'FROM #inv_prov main'
      '     INNER JOIN (SELECT docNumber, sprSum, idPredpr'
      '                FROM #inv_prov'
      '                GROUP BY docNumber, sprSum, idPredpr'
      
        '                HAVING COUNT(*)>1) grp ON main.docNumber=grp.doc' +
        'Number AND main.sprSum=grp.sprSum AND main.idPredpr=grp.idPredpr'
      
        '     LEFT JOIN #inv_prov esf ON main.docNumber=esf.docNumber AND' +
        ' main.sprSum=esf.sprSum AND main.idPredpr=esf.idPredpr AND esf.f' +
        'ullName is not NULL'
      '     LEFT JOIN tbPredpr pr ON main.idPredpr=pr.idPredpr '
      'WHERE main.fullName is NULL AND esf.fullName IS NOT NULL'
      'ORDER BY main.docNumber, main.fullName')
    Left = 320
    Top = 200
    object SelectDuplicateProvNumBuhSpr: TStringField
      DisplayLabel = #1057#1087#1088#1072#1074#1082#1072'|'#8470' '#1073#1091#1093'. '#1089#1087#1088'.'
      FieldName = 'NumBuhSpr'
      Size = 10
    end
    object SelectDuplicateProvdocNumber: TStringField
      DisplayLabel = #1057#1087#1088#1072#1074#1082#1072'|'#8470' '#1076#1086#1082#1091#1084#1077#1085#1090#1072
      FieldName = 'docNumber'
      Size = 30
    end
    object SelectDuplicateProvdocDate: TDateTimeField
      DisplayLabel = #1057#1087#1088#1072#1074#1082#1072'|'#1044#1072#1090#1072' '#1076#1086#1082#1091#1084#1077#1085#1090#1072
      FieldName = 'docDate'
    end
    object SelectDuplicateProvsprSum: TBCDField
      DisplayLabel = #1057#1087#1088#1072#1074#1082#1072'|'#1057#1091#1084#1084#1072' '#1053#1044#1057
      FieldName = 'sprSum'
      Precision = 18
      Size = 3
    end
    object SelectDuplicateProvnumBuhinv: TStringField
      DisplayLabel = #1069#1057#1063#1060'|'#8470' '#1073#1091#1093'. '#1089#1087#1088
      FieldName = 'numBuhinv'
      Size = 10
    end
    object SelectDuplicateProvfullName: TStringField
      DisplayLabel = #1069#1057#1063#1060'|'#1053#1086#1084#1077#1088
      FieldName = 'fullName'
      Size = 30
    end
    object SelectDuplicateProvtotalVat: TBCDField
      DisplayLabel = #1069#1057#1063#1060'|'#1057#1091#1084#1084#1072' '#1053#1044#1057
      FieldName = 'totalVat'
      Precision = 18
      Size = 3
    end
    object SelectDuplicateProvnamePredpr: TStringField
      DisplayLabel = #1050#1086#1085#1090#1088#1072#1075#1077#1085#1090
      FieldName = 'namePredpr'
      Size = 150
    end
    object SelectDuplicateProvdopUNN: TSmallintField
      DisplayLabel = #1060#1080#1083#1080#1072#1083
      FieldName = 'dopUNN'
    end
  end
  object CrSvodDuples: TADOQuery
    Connection = SvodMDBConnection
    CommandTimeout = 120
    Parameters = <>
    SQL.Strings = (
      'if object_id('#39'tempdb..#svod_duples'#39','#39'U'#39') is not NULL'
      'drop table tempdb..#svod_duples'
      ''
      'CREATE TABLE tempdb..#svod_duples('
      'numbuhdup VARCHAR(10),'
      'docnumberdup VARCHAR(30),'
      'docdatedup DATETIME,'
      'sumdup DECIMAL(18, 3),'
      'numbuhsv VARCHAR(10),'
      'invfullname VARCHAR(25),'
      'invtotalvat DECIMAL(18, 3),'
      'namepredpr VARCHAR(150),'
      'dopUNN smallint'
      ')'
      '')
    Left = 360
    Top = 16
  end
  object CrSvodInv: TADOQuery
    Connection = SvodMDBConnection
    CommandTimeout = 120
    Parameters = <>
    SQL.Strings = (
      'if object_id('#39'tempdb..#svod_inv'#39','#39'U'#39') is not NULL'
      'drop table tempdb..#svod_inv'
      ''
      'CREATE TABLE tempdb..#svod_inv('
      'idPredpr bigint,'
      'invoicefullname varchar(25),'
      'datetrans datetime,'
      'status tinyint,'
      'docnumber varchar(50),'
      'docdate datetime,'
      'ndsspr decimal(18, 3),'
      'ndsinvoice decimal(18, 3),'
      'totalcostinv decimal(18, 3),'
      'totalcostvatinv decimal(18, 3),'
      'filial smallint,'
      'svplace varchar(1),'
      'numbuhspr varchar(10),'
      'numdocpart varchar(50))')
    Left = 360
    Top = 64
  end
  object CrInvProv: TADOQuery
    Connection = ObjMDBConnection
    CommandTimeout = 120
    Parameters = <>
    SQL.Strings = (
      'if object_id('#39'tempdb..#inv_prov'#39','#39'U'#39') is not NULL'
      'drop table tempdb..#inv_prov'
      ''
      'CREATE TABLE tempdb..#inv_prov('
      'fullName VARCHAR(30),'
      'documentType tinyint,'
      'invStatus smallint,'
      'dateTrans DATETIME,'
      'docNumber VARCHAR(30),'
      'docDate DATETIME,'
      'sprSum NUMERIC(18, 3),'
      'totalVat DECIMAL(18, 3),'
      'totalCost DECIMAL(18, 3),'
      'totalCostVat DECIMAL(18, 3),'
      'dopUnn smallint,'
      'NumBuhSpr VARCHAR(10),'
      'idPredpr int,'
      'globalcode bigint,'
      'NumDocPart VARCHAR(50)'
      ')')
    Left = 112
    Top = 200
  end
  object InsSvodDuplesQ: TADOQuery
    Connection = SvodMDBConnection
    CommandTimeout = 900
    Parameters = <
      item
        Name = 'numbuhdup'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 10
        Value = Null
      end
      item
        Name = 'docnumberdup'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 30
        Value = Null
      end
      item
        Name = 'docdatedup'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'sumdup'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'numbuhsv'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 10
        Value = Null
      end
      item
        Name = 'invfullname'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 25
        Value = Null
      end
      item
        Name = 'invtotalvat'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'namepredpr'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 150
        Value = Null
      end
      item
        Name = 'dopUNN'
        Attributes = [paSigned, paNullable]
        DataType = ftSmallint
        Precision = 5
        Size = 2
        Value = Null
      end>
    SQL.Strings = (
      
        'INSERT INTO #svod_duples(numbuhdup, docnumberdup, docdatedup, su' +
        'mdup, numbuhsv, invfullname, invtotalvat, namepredpr, dopUNN)'
      
        'VALUES(:numbuhdup, :docnumberdup, :docdatedup, :sumdup, :numbuhs' +
        'v, :invfullname, :invtotalvat, :namepredpr, :dopUNN)')
    Left = 392
    Top = 16
  end
  object InsSvodInvQ: TADOQuery
    Connection = SvodMDBConnection
    CommandTimeout = 900
    Parameters = <
      item
        Name = 'idPredpr'
        Attributes = [paSigned, paNullable]
        DataType = ftLargeint
        Precision = 19
        Size = 8
        Value = Null
      end
      item
        Name = 'invoicefullname'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 25
        Value = Null
      end
      item
        Name = 'datetrans'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'status'
        Attributes = [paNullable]
        DataType = ftWord
        Precision = 3
        Size = 1
        Value = Null
      end
      item
        Name = 'docnumber'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'docdate'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'ndsspr'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'ndsinvoice'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'totalcostinv'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'totalcostvatinv'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'filial'
        Attributes = [paSigned, paNullable]
        DataType = ftSmallint
        Precision = 5
        Size = 2
        Value = Null
      end
      item
        Name = 'svplace'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 1
        Value = Null
      end
      item
        Name = 'numbuhspr'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 10
        Value = Null
      end
      item
        Name = 'numdocpart'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end>
    SQL.Strings = (
      
        'INSERT INTO #svod_inv(idPredpr, invoicefullname, datetrans, stat' +
        'us, docnumber, docdate, ndsspr, ndsinvoice, totalcostinv, totalc' +
        'ostvatinv, filial, svplace, numbuhspr, numdocpart)'
      
        'VALUES(:idPredpr, :invoicefullname, :datetrans, :status, :docnum' +
        'ber, :docdate, :ndsspr, :ndsinvoice, :totalcostinv, :totalcostva' +
        'tinv, :filial, :svplace, :numbuhspr, :numdocpart)')
    Left = 392
    Top = 64
  end
  object SelectSvodDuplesFilial: TADOQuery
    Connection = SvodMDBConnection
    CursorType = ctStatic
    CommandTimeout = 900
    Parameters = <>
    SQL.Strings = (
      'SELECT *'
      'FROM #svod_duples')
    Left = 424
    Top = 16
    object SelectSvodDuplesFilialnumbuhdup: TStringField
      DisplayLabel = #1057#1087#1088#1072#1074#1082#1072'|'#8470' '#1073#1091#1093'. '#1089#1087#1088'.'
      DisplayWidth = 11
      FieldName = 'numbuhdup'
      Size = 10
    end
    object SelectSvodDuplesFilialdocnumberdup: TStringField
      DisplayLabel = #1057#1087#1088#1072#1074#1082#1072'|'#8470' '#1076#1086#1082#1091#1084#1077#1085#1090#1072
      FieldName = 'docnumberdup'
      Size = 30
    end
    object SelectSvodDuplesFilialdocdatedup: TDateTimeField
      DisplayLabel = #1057#1087#1088#1072#1074#1082#1072'|'#1044#1072#1090#1072' '#1076#1086#1082#1091#1084#1077#1085#1090#1072
      FieldName = 'docdatedup'
    end
    object SelectSvodDuplesFilialsumdup: TBCDField
      DisplayLabel = #1057#1087#1088#1072#1074#1082#1072'|'#1057#1091#1084#1084#1072' '#1053#1044#1057
      FieldName = 'sumdup'
      Precision = 18
      Size = 3
    end
    object SelectSvodDuplesFilialnumbuhsv: TStringField
      DisplayLabel = #1069#1057#1063#1060'|'#8470' '#1073#1091#1093'. '#1089#1087#1088
      DisplayWidth = 11
      FieldName = 'numbuhsv'
      Size = 10
    end
    object SelectSvodDuplesFilialinvfullname: TStringField
      DisplayLabel = #1069#1057#1063#1060'|'#1053#1086#1084#1077#1088
      FieldName = 'invfullname'
      Size = 25
    end
    object SelectSvodDuplesFilialinvtotalvat: TBCDField
      DisplayLabel = #1069#1057#1063#1060'|'#1057#1091#1084#1084#1072' '#1053#1044#1057
      FieldName = 'invtotalvat'
      Precision = 18
      Size = 3
    end
    object SelectSvodDuplesFilialnamepredpr: TStringField
      DisplayLabel = #1050#1086#1085#1090#1088#1072#1075#1077#1085#1090
      DisplayWidth = 70
      FieldName = 'namepredpr'
      Size = 150
    end
    object SelectSvodDuplesFilialdopUNN: TSmallintField
      DisplayLabel = #1060#1080#1083#1080#1072#1083
      FieldName = 'dopUNN'
    end
  end
  object SelectSvodDuplesDS: TDataSource
    DataSet = SelectSvodDuplesFilial
    Left = 456
    Top = 16
  end
  object SelectSvodInv: TADOQuery
    Connection = SvodMDBConnection
    CursorType = ctStatic
    CommandTimeout = 900
    Parameters = <
      item
        Name = 'FirstDate'
        DataType = ftString
        Size = 10
        Value = '01.01.2020'
      end
      item
        Name = 'SecondDate'
        DataType = ftString
        Size = 10
        Value = '31.01.2020'
      end>
    SQL.Strings = (
      'SET DATEFORMAT DMY'
      ''
      'DECLARE @FirstDate DATETIME,'
      '                @SecondDate DATETIME'
      ''
      'SET @FirstDate = CAST(:FirstDate AS DATETIME)'
      'SET @SecondDate = CAST(:SecondDate AS DATETIME)'
      ''
      
        'SELECT ISNULL(inv.idPredpr, exc.idPredpr) AS idPredpr, ISNULL(in' +
        'v.invoicefullname, exc.invoicefullname) AS invoicefullname, ISNU' +
        'LL(inv.datetrans, exc.datetrans) AS datetrans, '
      
        '             ISNULL(inv.status, exc.status) AS status, exc.recip' +
        'ientname, exc.signerfio,'
      
        '             ISNULL(exc.namepredpr, pred.UNN+CASE WHEN (pred.dop' +
        'UNN IS NOT NULL) AND (pred.dopUNN>1) THEN '#39' '#39'+CAST(pred.dopUNN A' +
        'S VARCHAR) ELSE '#39#39'  END+'#39' - '#39'+pred.namePredpr) as namepredpr,  '
      
        '             ISNULL(inv.docnumber, exc.docnumber) AS docnumber, ' +
        'ISNULL(inv.docdate , exc.docdate) AS docdate,  exc.ndsexcel, inv' +
        '.ndsspr, '
      
        '             inv.ndsinvoice, ISNULL(inv.totalcostinv, exc.totalc' +
        'ostinv) AS totalcostinv, ISNULL(inv.totalcostvatinv, exc.totalco' +
        'stvatinv) AS totalcostvatinv, ISNULL(inv.filial, exc.dopunn) AS ' +
        'filial,'
      
        '             ISNULL(inv.svplace, exc.svplace) AS svplace, inv.nu' +
        'mbuhspr, inv.numdocpart '
      'FROM #svod_inv inv'
      '          LEFT JOIN tbPredpr pred ON inv.idPredpr=pred.idPredpr'
      '          FULL JOIN (SELECT * '
      '                             FROM #svexceltmp exc'
      
        '                             WHERE  ((exc.datetrans BETWEEN @Fir' +
        'stDate AND @SecondDate) OR (exc.docdate BETWEEN @FirstDate  AND ' +
        '@SecondDate))) exc '
      
        '                             ON (inv.invoicefullname=exc.invoice' +
        'fullname) -- OR ((ISNULL(inv.docnumber,'#39#39')=ISNULL(exc.docnumber,' +
        #39#39')) AND (ISNULL(inv.ndsspr,0)=ISNULL(exc.ndsexcel,0)) AND (ISNU' +
        'LL(inv.docdate,CAST('#39'01.01.2000'#39' AS DATETIME))=ISNULL(exc.docdat' +
        'e,CAST('#39'01.01.2000'#39' AS DATETIME)))) '
      
        'WHERE (((inv.ndsinvoice IS NULL) OR (exc.ndsexcel IS NULL) OR (i' +
        'nv.ndsspr IS NULL)) OR ((inv.ndsspr IS NOT NULL) AND (exc.ndsexc' +
        'el IS NOT NULL) AND (inv.ndsspr<>exc.ndsexcel)))'
      '-- '#1059#1089#1083#1086#1074#1080#1077' '#1087#1088#1077#1076#1087#1088#1080#1103#1090#1080#1103
      '-- ORDER BY ISNULL(inv.invoicefullname, exc.invoicefullname)')
    Left = 424
    Top = 64
    object SelectSvodInvidPredpr: TLargeintField
      FieldName = 'idPredpr'
      ReadOnly = True
    end
    object SelectSvodInvinvoicefullname: TStringField
      DisplayLabel = #1069#1057#1063#1060'|'#1053#1086#1084#1077#1088
      FieldName = 'invoicefullname'
      ReadOnly = True
      Size = 25
    end
    object SelectSvodInvdatetrans: TDateTimeField
      FieldName = 'datetrans'
      ReadOnly = True
    end
    object SelectSvodInvstatus: TWordField
      FieldName = 'status'
      ReadOnly = True
    end
    object SelectSvodInvrecipientname: TStringField
      FieldName = 'recipientname'
      ReadOnly = True
      Size = 200
    end
    object SelectSvodInvsignerfio: TStringField
      FieldName = 'signerfio'
      ReadOnly = True
      Size = 70
    end
    object SelectSvodInvnamepredpr: TStringField
      FieldName = 'namepredpr'
      ReadOnly = True
      Size = 150
    end
    object SelectSvodInvdocnumber: TStringField
      FieldName = 'docnumber'
      ReadOnly = True
      Size = 50
    end
    object SelectSvodInvdocdate: TDateTimeField
      FieldName = 'docdate'
      ReadOnly = True
    end
    object SelectSvodInvndsexcel: TBCDField
      FieldName = 'ndsexcel'
      Precision = 18
      Size = 3
    end
    object SelectSvodInvndsspr: TBCDField
      FieldName = 'ndsspr'
      Precision = 18
      Size = 3
    end
    object SelectSvodInvndsinvoice: TBCDField
      FieldName = 'ndsinvoice'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object SelectSvodInvtotalcostinv: TBCDField
      FieldName = 'totalcostinv'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object SelectSvodInvtotalcostvatinv: TBCDField
      FieldName = 'totalcostvatinv'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object SelectSvodInvfilial: TSmallintField
      FieldName = 'filial'
    end
    object SelectSvodInvsvplace: TStringField
      FieldName = 'svplace'
      ReadOnly = True
      Size = 1
    end
    object SelectSvodInvnumbuhspr: TStringField
      FieldName = 'numbuhspr'
      Size = 10
    end
    object SelectSvodInvnumdocpart: TStringField
      FieldName = 'numdocpart'
      Size = 50
    end
  end
  object SelectSprProvQ: TADOQuery
    Connection = SvodMDBConnection
    CursorType = ctStatic
    CommandTimeout = 900
    Parameters = <
      item
        Name = 'numdoc'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'numdocpart'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'datadoc'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'numbuhspr'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 10
        Value = Null
      end
      item
        Name = 'globalcode'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'filial'
        Attributes = [paSigned, paNullable]
        DataType = ftSmallint
        Precision = 5
        Size = 2
        Value = Null
      end
      item
        Name = 'invfullname'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 25
        Value = Null
      end>
    SQL.Strings = (
      
        'SELECT numbuhspr, datadoc,  numdoc, numdocpart, summ, globalcode' +
        ', filial, NSF'
      'FROM #svod_prov prov'
      
        'WHERE prov.numdoc=:numdoc AND prov.numdocpart=:numdocpart AND da' +
        'tadoc=:datadoc AND numbuhspr=:numbuhspr '
      
        '             AND globalcode=:globalcode AND filial=:filial AND S' +
        'ubstring(ISNULL(NSF,'#39#39'),3,25)=:invfullname')
    Left = 424
    Top = 112
  end
  object SelectSprProvDS: TDataSource
    DataSet = SelectSprProvQ
    Left = 456
    Top = 112
  end
  object InsSprProvQ: TADOQuery
    Connection = SvodMDBConnection
    CommandTimeout = 900
    Parameters = <
      item
        Name = 'numbuhspr'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 10
        Value = Null
      end
      item
        Name = 'datadoc'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'numdoc'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'numdocpart'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'summ'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'globalcode'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'filial'
        Attributes = [paSigned, paNullable]
        DataType = ftSmallint
        Precision = 5
        Size = 2
        Value = Null
      end
      item
        Name = 'NSF'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 30
        Value = Null
      end>
    SQL.Strings = (
      
        'INSERT INTO #svod_prov(numbuhspr, datadoc,  numdoc, numdocpart, ' +
        'summ, globalcode, filial, NSF)'
      
        'VALUES(:numbuhspr, :datadoc, :numdoc, :numdocpart, :summ, :globa' +
        'lcode, :filial, :NSF)')
    Left = 392
    Top = 112
  end
  object CrSprProv: TADOQuery
    Connection = SvodMDBConnection
    CommandTimeout = 120
    Parameters = <>
    SQL.Strings = (
      'if object_id('#39'tempdb..#svod_prov'#39','#39'U'#39') is not NULL'
      'drop table tempdb..#svod_prov'
      ''
      'CREATE TABLE tempdb..#svod_prov('
      'numbuhspr varchar(10),'
      'datadoc datetime,'
      'numdoc varchar(50),'
      'numdocpart varchar(50),'
      'summ decimal(18, 3),'
      'globalcode varchar(50),'
      'filial smallint,'
      'NSF varchar(30))'
      '')
    Left = 360
    Top = 112
  end
  object SelectSprProvObj: TADOQuery
    Connection = ObjMDBConnection
    CursorType = ctStatic
    CommandTimeout = 900
    Parameters = <
      item
        Name = 'FirstDate'
        DataType = ftString
        Size = 10
        Value = '01.01.2020'
      end
      item
        Name = 'SecondDate'
        DataType = ftString
        Size = 10
        Value = '31.01.2020'
      end>
    SQL.Strings = (
      'SET DATEFORMAT DMY'
      ''
      'DECLARE @FirstDate DATETIME,'
      '        @SecondDate DATETIME,'
      '        @dopUnn smallint'
      ''
      'SET @FirstDate = CAST(:FirstDate AS DATETIME)'
      'SET @SecondDate = CAST(:SecondDate AS DATETIME)'
      ''
      
        'SELECT @dopUnn=dopUNN FROM tbPredpr WHERE idPredpr=(SELECT idPre' +
        'dpr FROM tbNastrPredpr) '
      ''
      'SELECT spr.Summ, spr.DataDoc, '
      '             -- spr.NumDoc, '
      
        '             substring(spr.NumDoc, patindex('#39'%[^0]%'#39', spr.NumDoc' +
        '), 50) AS NumDoc, '
      
        '             spr.numDocPart, spr.NumBuhSpr, pred.globalcode, @do' +
        'pUnn as dopUNN, spr.NSF'
      'FROM buh.dbo.tbSpravka spr'
      
        '           INNER JOIN buh.dbo.tbSFProvNDS prov ON spr.idSchetSub' +
        'SchetDT=prov.IdDt AND spr.PrizAUDT=prov.AuDt AND'
      
        '                                                                ' +
        '                   spr.idSchetSubSchetKT=prov.IdKt AND spr.PrizA' +
        'UKT=prov.AuKt'
      '          LEFT JOIN tbPredpr pred ON spr.idPredpr=pred.idPredpr'
      
        'WHERE (DataDoc BETWEEN @FirstDate and @SecondDate) AND PrizRej=1' +
        ' AND Sv=0'
      '-- '#1059#1089#1083#1086#1074#1080#1077' '#1076#1083#1103' '#1087#1088#1077#1076#1087#1088#1080#1103#1090#1080#1103)
    Left = 360
    Top = 200
    object SelectSprProvObjSumm: TBCDField
      FieldName = 'Summ'
      Precision = 18
      Size = 3
    end
    object SelectSprProvObjDataDoc: TDateTimeField
      FieldName = 'DataDoc'
    end
    object SelectSprProvObjNumDoc: TStringField
      FieldName = 'NumDoc'
      Size = 50
    end
    object SelectSprProvObjnumDocPart: TStringField
      FieldName = 'numDocPart'
      Size = 50
    end
    object SelectSprProvObjNumBuhSpr: TStringField
      FieldName = 'NumBuhSpr'
      Size = 10
    end
    object SelectSprProvObjglobalcode: TStringField
      FieldName = 'globalcode'
      Size = 100
    end
    object SelectSprProvObjdopUNN: TSmallintField
      FieldName = 'dopUNN'
      ReadOnly = True
    end
    object SelectSprProvObjNSF: TStringField
      FieldName = 'NSF'
      Size = 30
    end
  end
  object SelectSvodDuplesOblpo: TADOQuery
    Connection = SvodMDBConnection
    CursorType = ctStatic
    CommandTimeout = 900
    Parameters = <>
    SQL.Strings = (
      'SET DATEFORMAT DMY'
      ''
      
        'SELECT inv.idPredpr, inv.invoicefullname, inv.datetrans, inv.sta' +
        'tus, pred.namePredpr, inv.docnumber, inv.docdate, inv.ndsspr, in' +
        'v.ndsinvoice, inv.totalcostinv, inv.totalcostvatinv, inv.filial,' +
        ' inv.numbuhspr, inv.numdocpart             '
      'FROM #svod_inv inv'
      '          LEFT JOIN tbPredpr pred ON inv.idPredpr=pred.idPredpr'
      
        '          INNER JOIN (SELECT invoicefullname,  docnumber, docdat' +
        'e, ndsspr, ndsinvoice'
      '                                FROM #svod_inv'
      
        '                                WHERE  ndsspr IS NOT NULL AND nd' +
        'sinvoice IS NOT NULL'
      
        '                                GROUP BY invoicefullname,  docnu' +
        'mber, docdate, ndsspr, ndsinvoice'
      
        '                                HAVING COUNT(*)>1) grp ON ISNULL' +
        '(inv.invoicefullname,'#39#39')=ISNULL(grp.invoicefullname,'#39#39') AND ISNU' +
        'LL(inv.docnumber,'#39#39')=ISNULL(grp.docnumber,'#39#39') AND '
      
        '                                                                ' +
        '                 ISNULL(inv.docdate,CAST('#39'01.01.2000'#39' AS DATETIM' +
        'E))=ISNULL(grp.docdate,CAST('#39'01.01.2000'#39' AS DATETIME)) AND inv.n' +
        'dsspr=grp.ndsspr AND inv.ndsinvoice=grp.ndsinvoice'
      'ORDER BY inv.invoicefullname')
    Left = 424
    Top = 160
    object SelectSvodDuplesOblpoidPredpr: TLargeintField
      FieldName = 'idPredpr'
    end
    object SelectSvodDuplesOblpoinvoicefullname: TStringField
      FieldName = 'invoicefullname'
      Size = 25
    end
    object SelectSvodDuplesOblpodatetrans: TDateTimeField
      FieldName = 'datetrans'
    end
    object SelectSvodDuplesOblpostatus: TWordField
      FieldName = 'status'
    end
    object SelectSvodDuplesOblponamePredpr: TStringField
      FieldName = 'namePredpr'
      Size = 150
    end
    object SelectSvodDuplesOblpodocnumber: TStringField
      FieldName = 'docnumber'
      Size = 50
    end
    object SelectSvodDuplesOblpodocdate: TDateTimeField
      FieldName = 'docdate'
    end
    object SelectSvodDuplesOblpondsspr: TBCDField
      FieldName = 'ndsspr'
      Precision = 18
      Size = 3
    end
    object SelectSvodDuplesOblpondsinvoice: TBCDField
      FieldName = 'ndsinvoice'
      Precision = 18
      Size = 3
    end
    object SelectSvodDuplesOblpototalcostinv: TBCDField
      FieldName = 'totalcostinv'
      Precision = 18
      Size = 3
    end
    object SelectSvodDuplesOblpototalcostvatinv: TBCDField
      FieldName = 'totalcostvatinv'
      Precision = 18
      Size = 3
    end
    object SelectSvodDuplesOblpofilial: TSmallintField
      FieldName = 'filial'
    end
    object SelectSvodDuplesOblponumbuhspr: TStringField
      FieldName = 'numbuhspr'
      Size = 10
    end
    object SelectSvodDuplesOblponumdocpart: TStringField
      FieldName = 'numdocpart'
      Size = 50
    end
  end
  object SelectSvodDuplesOblpoDS: TDataSource
    DataSet = SelectSvodDuplesOblpo
    Left = 456
    Top = 160
  end
  object SelectOblDopUnn: TADOQuery
    Connection = SvodMDBConnection
    Parameters = <>
    SQL.Strings = (
      'SELECT dopUNN '
      'FROM tbPredpr '
      
        'WHERE UNN=(SELECT UNN FROM tbPredpr WHERE idPredpr=(SELECT idPre' +
        'dpr FROM tbNastrPredpr)) AND idPredpr<>(SELECT idPredpr FROM tbN' +
        'astrPredpr)'
      'ORDER BY dopUNN')
    Left = 160
    Top = 16
  end
  object TmpComeralInvMemTableEh: TMemTableEh
    FieldDefs = <
      item
        Name = 'idRecord'
        DataType = ftAutoInc
        Precision = 15
      end
      item
        Name = 'idPredpr'
        DataType = ftLargeint
        Precision = 15
      end
      item
        Name = 'invoicefullname'
        DataType = ftString
        Size = 25
      end
      item
        Name = 'datetrans'
        DataType = ftDateTime
      end
      item
        Name = 'status'
        DataType = ftWord
        Precision = 15
      end
      item
        Name = 'recipientname'
        DataType = ftString
        Size = 200
      end
      item
        Name = 'signerfio'
        DataType = ftString
        Size = 70
      end
      item
        Name = 'namepredpr'
        DataType = ftString
        Size = 300
      end
      item
        Name = 'docnumber'
        DataType = ftString
        Size = 50
      end
      item
        Name = 'docdate'
        DataType = ftDateTime
      end
      item
        Name = 'ndsexcel'
        DataType = ftBCD
        Precision = 18
        Size = 3
      end
      item
        Name = 'ndsspr'
        DataType = ftBCD
        Precision = 18
        Size = 3
      end
      item
        Name = 'ndsinvoice'
        DataType = ftBCD
        Precision = 18
        Size = 3
      end
      item
        Name = 'totalcostinv'
        DataType = ftBCD
        Precision = 18
        Size = 3
      end
      item
        Name = 'totalcostvatinv'
        DataType = ftBCD
        Precision = 18
        Size = 3
      end
      item
        Name = 'filial'
        DataType = ftSmallint
        Precision = 15
      end
      item
        Name = 'svplace'
        DataType = ftString
        Size = 1
      end
      item
        Name = 'numbuhspr'
        DataType = ftString
        Size = 10
      end
      item
        Name = 'numdocpart'
        DataType = ftString
        Size = 50
      end
      item
        Name = 'hide'
        DataType = ftBoolean
      end>
    FetchAllOnOpen = True
    IndexDefs = <>
    Params = <>
    DataDriver = SelectTmpComeralInvDSDEh
    StoreDefs = True
    OnCalcFields = TmpComeralInvMemTableEhCalcFields
    Left = 727
    Top = 66
    object TmpComeralInvMemTableEhnamepredpr: TStringField
      FieldName = 'namepredpr'
      ReadOnly = True
      Size = 300
    end
    object TmpComeralInvMemTableEhinvoicefullname: TStringField
      FieldName = 'invoicefullname'
      ReadOnly = True
      Size = 25
    end
    object TmpComeralInvMemTableEhdatetrans: TDateTimeField
      FieldName = 'datetrans'
      ReadOnly = True
    end
    object TmpComeralInvMemTableEhStatusText: TStringField
      FieldKind = fkCalculated
      FieldName = 'StatusText'
      ReadOnly = True
      Size = 50
      Calculated = True
    end
    object TmpComeralInvMemTableEhrecipientname: TStringField
      FieldName = 'recipientname'
      ReadOnly = True
      Size = 200
    end
    object TmpComeralInvMemTableEhsignerfio: TStringField
      FieldName = 'signerfio'
      ReadOnly = True
      Size = 70
    end
    object TmpComeralInvMemTableEhdocnumber: TStringField
      FieldName = 'docnumber'
      ReadOnly = True
      Size = 50
    end
    object TmpComeralInvMemTableEhdocdate: TDateTimeField
      FieldName = 'docdate'
      ReadOnly = True
    end
    object TmpComeralInvMemTableEhndsexcel: TBCDField
      FieldName = 'ndsexcel'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object TmpComeralInvMemTableEhndsspr: TBCDField
      FieldName = 'ndsspr'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object TmpComeralInvMemTableEhndsinvoice: TBCDField
      FieldName = 'ndsinvoice'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object TmpComeralInvMemTableEhndsdiff: TBCDField
      FieldKind = fkCalculated
      FieldName = 'ndsdiff'
      ReadOnly = True
      Calculated = True
    end
    object TmpComeralInvMemTableEhtotalcostinv: TBCDField
      FieldName = 'totalcostinv'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object TmpComeralInvMemTableEhtotalcostvatinv: TBCDField
      FieldName = 'totalcostvatinv'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object TmpComeralInvMemTableEhfilial: TSmallintField
      FieldName = 'filial'
      ReadOnly = True
    end
    object TmpComeralInvMemTableEhsvplace: TStringField
      FieldName = 'svplace'
      ReadOnly = True
      Size = 1
    end
    object TmpComeralInvMemTableEhnumbuhspr: TStringField
      FieldName = 'numbuhspr'
      ReadOnly = True
      Size = 10
    end
    object TmpComeralInvMemTableEhnumdocpart: TStringField
      FieldName = 'numdocpart'
      ReadOnly = True
      Size = 50
    end
    object TmpComeralInvMemTableEhhide: TBooleanField
      DisplayLabel = #1055#1088#1086#1074'.'
      FieldName = 'hide'
    end
    object TmpComeralInvMemTableEhidRecord: TAutoIncField
      FieldName = 'idRecord'
      ReadOnly = True
    end
    object TmpComeralInvMemTableEhidPredpr: TLargeintField
      FieldName = 'idPredpr'
      ReadOnly = True
    end
    object TmpComeralInvMemTableEhstatus: TWordField
      FieldName = 'status'
      ReadOnly = True
    end
  end
  object TmpComeralInvMemTableEhDS: TDataSource
    DataSet = TmpComeralInvMemTableEh
    Left = 760
    Top = 64
  end
  object SelectTmpComeralInvDSDEh: TDataSetDriverEh
    KeyFields = 'idRecord'
    ProviderDataSet = SelectTmpComeralInv
    Left = 696
    Top = 64
  end
  object SelectTmpComeralInv: TADOQuery
    Connection = SvodMDBConnection
    CursorType = ctStatic
    CommandTimeout = 900
    Parameters = <>
    SQL.Strings = (
      'SELECT *'
      'FROM tmpComeralInv'
      '-- '#1059#1089#1083#1086#1074#1080#1077' '#1087#1088#1077#1076#1087#1088#1080#1103#1090#1080#1103)
    Left = 664
    Top = 64
    object SelectTmpComeralInvidRecord: TAutoIncField
      FieldName = 'idRecord'
      ReadOnly = True
    end
    object SelectTmpComeralInvidPredpr: TLargeintField
      FieldName = 'idPredpr'
      ReadOnly = True
    end
    object SelectTmpComeralInvinvoicefullname: TStringField
      FieldName = 'invoicefullname'
      ReadOnly = True
      Size = 25
    end
    object SelectTmpComeralInvdatetrans: TDateTimeField
      FieldName = 'datetrans'
      ReadOnly = True
    end
    object SelectTmpComeralInvstatus: TWordField
      FieldName = 'status'
      ReadOnly = True
    end
    object SelectTmpComeralInvrecipientname: TStringField
      FieldName = 'recipientname'
      ReadOnly = True
      Size = 200
    end
    object SelectTmpComeralInvsignerfio: TStringField
      FieldName = 'signerfio'
      ReadOnly = True
      Size = 70
    end
    object SelectTmpComeralInvnamepredpr: TStringField
      FieldName = 'namepredpr'
      ReadOnly = True
      Size = 300
    end
    object SelectTmpComeralInvdocnumber: TStringField
      FieldName = 'docnumber'
      ReadOnly = True
      Size = 50
    end
    object SelectTmpComeralInvdocdate: TDateTimeField
      FieldName = 'docdate'
      ReadOnly = True
    end
    object SelectTmpComeralInvndsexcel: TBCDField
      FieldName = 'ndsexcel'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object SelectTmpComeralInvndsspr: TBCDField
      FieldName = 'ndsspr'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object SelectTmpComeralInvndsinvoice: TBCDField
      FieldName = 'ndsinvoice'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object SelectTmpComeralInvtotalcostinv: TBCDField
      FieldName = 'totalcostinv'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object SelectTmpComeralInvtotalcostvatinv: TBCDField
      FieldName = 'totalcostvatinv'
      ReadOnly = True
      Precision = 18
      Size = 3
    end
    object SelectTmpComeralInvfilial: TSmallintField
      FieldName = 'filial'
      ReadOnly = True
    end
    object SelectTmpComeralInvsvplace: TStringField
      FieldName = 'svplace'
      ReadOnly = True
      Size = 1
    end
    object SelectTmpComeralInvnumbuhspr: TStringField
      FieldName = 'numbuhspr'
      ReadOnly = True
      Size = 10
    end
    object SelectTmpComeralInvnumdocpart: TStringField
      FieldName = 'numdocpart'
      ReadOnly = True
      Size = 50
    end
    object SelectTmpComeralInvhide: TBooleanField
      FieldName = 'hide'
    end
  end
  object SelectTmpComeralProvDS: TDataSource
    DataSet = SelectTmpComeralProv
    Left = 696
    Top = 112
  end
  object SelectTmpComeralProv: TADOQuery
    Connection = SvodMDBConnection
    CursorType = ctStatic
    CommandTimeout = 900
    Parameters = <
      item
        Name = 'numdoc'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'numdocpart'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'datadoc'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'numbuhspr'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 10
        Value = Null
      end
      item
        Name = 'globalcode'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'filial'
        Attributes = [paSigned, paNullable]
        DataType = ftSmallint
        Precision = 5
        Size = 2
        Value = Null
      end
      item
        Name = 'invfullname'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 25
        Value = Null
      end>
    SQL.Strings = (
      
        'SELECT numbuhspr, datadoc,  numdoc, numdocpart, summ, globalcode' +
        ', filial, NSF'
      'FROM tmpComeralProv prov'
      
        'WHERE prov.numdoc=:numdoc AND prov.numdocpart=:numdocpart AND da' +
        'tadoc=:datadoc AND numbuhspr=:numbuhspr '
      
        '             AND globalcode=:globalcode AND filial=:filial AND S' +
        'ubstring(ISNULL(NSF,'#39#39'),3,25)=:invfullname'
      ''
      '')
    Left = 664
    Top = 112
  end
  object InsTmpComeralInvQ: TADOQuery
    Connection = SvodMDBConnection
    CommandTimeout = 900
    Parameters = <
      item
        Name = 'idPredpr'
        Attributes = [paSigned, paNullable]
        DataType = ftLargeint
        Precision = 19
        Size = 8
        Value = Null
      end
      item
        Name = 'invoicefullname'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 25
        Value = Null
      end
      item
        Name = 'datetrans'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'status'
        Attributes = [paNullable]
        DataType = ftWord
        Precision = 3
        Size = 1
        Value = Null
      end
      item
        Name = 'recipientname'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 200
        Value = Null
      end
      item
        Name = 'signerfio'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 70
        Value = Null
      end
      item
        Name = 'namepredpr'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 300
        Value = Null
      end
      item
        Name = 'docnumber'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'docdate'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'ndsexcel'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'ndsspr'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'ndsinvoice'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'totalcostinv'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'totalcostvatinv'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'filial'
        Attributes = [paSigned, paNullable]
        DataType = ftSmallint
        Precision = 5
        Size = 2
        Value = Null
      end
      item
        Name = 'svplace'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 1
        Value = Null
      end
      item
        Name = 'numbuhspr'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 10
        Value = Null
      end
      item
        Name = 'numdocpart'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end>
    SQL.Strings = (
      
        'INSERT INTO [tmpComeralInv]([idPredpr], [invoicefullname], [date' +
        'trans], [status], [recipientname], [signerfio], [namepredpr], [d' +
        'ocnumber], [docdate], [ndsexcel], [ndsspr], [ndsinvoice], [total' +
        'costinv], [totalcostvatinv], [filial], [svplace], [numbuhspr], [' +
        'numdocpart])'
      
        'VALUES(:idPredpr, :invoicefullname, :datetrans, :status, :recipi' +
        'entname, :signerfio, :namepredpr, :docnumber, :docdate, :ndsexce' +
        'l, :ndsspr, :ndsinvoice, :totalcostinv, :totalcostvatinv, :filia' +
        'l, :svplace, :numbuhspr, :numdocpart)')
    Left = 632
    Top = 64
  end
  object InsTmpComeralProvQ: TADOQuery
    Connection = SvodMDBConnection
    Parameters = <
      item
        Name = 'numbuhspr'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 10
        Value = Null
      end
      item
        Name = 'datadoc'
        Attributes = [paNullable]
        DataType = ftDateTime
        NumericScale = 3
        Precision = 23
        Size = 16
        Value = Null
      end
      item
        Name = 'numdoc'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'numdocpart'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'summ'
        Attributes = [paSigned, paNullable]
        DataType = ftBCD
        NumericScale = 3
        Precision = 18
        Size = 19
        Value = Null
      end
      item
        Name = 'globalcode'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 50
        Value = Null
      end
      item
        Name = 'filial'
        Attributes = [paSigned, paNullable]
        DataType = ftSmallint
        Precision = 5
        Size = 2
        Value = Null
      end
      item
        Name = 'NSF'
        Attributes = [paNullable]
        DataType = ftString
        NumericScale = 255
        Precision = 255
        Size = 30
        Value = Null
      end>
    SQL.Strings = (
      
        'INSERT INTO [tmpComeralProv]([numbuhspr], [datadoc], [numdoc], [' +
        'numdocpart], [summ], [globalcode], [filial], [NSF])'
      
        'VALUES(:numbuhspr, :datadoc, :numdoc, :numdocpart, :summ, :globa' +
        'lcode, :filial, :NSF)')
    Left = 632
    Top = 112
  end
  object RewriteInsTmpComeralProv: TADOQuery
    Connection = SvodMDBConnection
    CommandTimeout = 900
    Parameters = <>
    SQL.Strings = (
      'DELETE FROM tmpComeralProv'
      ''
      
        'INSERT INTO [maindatabase_s].[dbo].[tmpComeralProv]([numbuhspr],' +
        ' [datadoc], [numdoc], [numdocpart], [summ], [globalcode], [filia' +
        'l], [NSF])'
      
        'SELECT numbuhspr, datadoc,  numdoc, numdocpart, summ, globalcode' +
        ', filial, NSF'
      'FROM #svod_prov')
    Left = 600
    Top = 112
  end
  object DelTmpComeralInvQ: TADOQuery
    Connection = SvodMDBConnection
    CommandTimeout = 900
    Parameters = <>
    SQL.Strings = (
      'DELETE FROM tmpComeralInv')
    Left = 600
    Top = 64
  end
end
